package com.yanqu.road.server.logic.activity.condition.normal;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.yuanbaolottery.YuanBaoLotteryModule;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;
import com.yanqu.road.server.manger.activity.ActivityMgr;

import java.math.BigInteger;

/**
 * 累充活动
 */
public class RoundVipExpActivityCondition extends BaseActivityCondition {

	public RoundVipExpActivityCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
		super(activityInfo, activityConditionInfo, baseActivityData);
	}

	@Override
	public void addTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.RoundVipExp.getValue(), handle);
	}

	@Override
	public void removeTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.RoundVipExp.getValue(), handle);
	}

	public boolean isCompleted(GamePlayer player) {
		int round = player.getModule(YuanBaoLotteryModule.class).getRound();
		int checkRound = activityConditionInfo.getParamList().get(2).intValue();
		if (round != checkRound) {
			return false;
		}
		return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
	}

	@Override
	protected void player_BoardLevelHandle(Object object) {
		int round = player.getModule(YuanBaoLotteryModule.class).getRound();
		int checkRound = activityConditionInfo.getParamList().get(2).intValue();
		if (round != checkRound) {
			return;
		}
		long addVip = (long) object;
		BigInteger newValue = getValue().add(BigInteger.valueOf(addVip));
		setValue(newValue);
	}

//	@Override
//	public void initDefaultValue() {
//		if (getValue().compareTo(BigInteger.ZERO) == 0) {
//			long money = player.getModule(AttributeModule.class).getAttribute(ePlayerAttrType.DayTotalRecharge);
//			if (money > 0) {
//				changeValue(money);
//			}
//		}
//	}

	@Override
	public boolean canChange(ActivityInfo activityInfo) {
		return ActivityMgr.activityInTime(activityInfo);
	}




}
